package com.pingbu.tijian.hospital.backapi.service;


import com.pingbu.common.bean.ResultBean;
import com.pingbu.tijian.hospital.backapi.bean.entity.Student;
import com.pingbu.tijian.hospital.backapi.bean.entity.StudentGroup;
import com.pingbu.tijian.hospital.backapi.bean.vo.GroupWithStudents;
import com.pingbu.tijian.hospital.backapi.mapper.StudentGroupMapper;
import com.pingbu.tijian.hospital.backapi.mapper.UserInfoMapper;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudentGroupExtendService {

    private static Logger logger = LoggerFactory.getLogger(StudentGroupExtendService.class);

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private StudentGroupMapper studentGroupMapper;
    @Autowired
    private StudentService  studentService;

    /**
     * 获取所有学生组下的学生
     * @param param
     * @return
     */
    public ResultBean<List<GroupWithStudents>> list(StudentGroup param){
        List<StudentGroup> lst1 = studentGroupMapper.list(param);

        // 转换为 GroupWithStudents
        List<GroupWithStudents> gwsList=new ArrayList<>();
        lst1.forEach((stg)->{
            GroupWithStudents gws = new GroupWithStudents();
            gws.setNoid(stg.getNoid());
            gws.setStudent_group_name(stg.getStudent_group_name());
            gws.setOrder_numb(stg.getOrder_numb());

            // 读取每个组的学生列表
            Student st1 = new Student();
            st1.setStudent_group_id(gws.getNoid());
            ResultBean<List<Student>> rbListStudents = studentService.list(st1);
            if(rbListStudents.getCode()==0){
                gws.setStudents(rbListStudents.getData());
            }
            gwsList.add(gws);
        });

        return ResultBean.create(0,"success",gwsList);
    }



}
